package org.wyf.EveryPoint.crowd.service.impl;

import org.wyf.EveryPoint.common.entity.QueryRequest;

import org.wyf.EveryPoint.crowd.entity.CollectionProject;
import org.wyf.EveryPoint.crowd.mapper.CollectionProjectMapper;
import org.wyf.EveryPoint.crowd.service.ICollectionProjectService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * 用户收藏表 Service实现
 *
 * @author wyf
 * @date 2021-04-26 16:43:18
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class CollectionProjectServiceImpl extends ServiceImpl<CollectionProjectMapper, CollectionProject> implements ICollectionProjectService {

    private final CollectionProjectMapper collectionProjectMapper;

    @Override
    public IPage<CollectionProject> findCollectionProjects(QueryRequest request, CollectionProject collectionProject) {
        LambdaQueryWrapper<CollectionProject> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<CollectionProject> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<CollectionProject> findCollectionProjects(CollectionProject collectionProject) {
	    LambdaQueryWrapper<CollectionProject> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createCollectionProject(CollectionProject collectionProject) {
        this.save(collectionProject);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateCollectionProject(CollectionProject collectionProject) {
        this.saveOrUpdate(collectionProject);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteCollectionProject(CollectionProject collectionProject) {
        LambdaQueryWrapper<CollectionProject> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}

    @Override
    public void deleteUserCollectionProject(Long projectId, Long userId) {
        this.baseMapper.deleteUserCollectionProject(projectId,userId);
    }

    @Override
    public List<CollectionProject> listUserCollection(Long projectId, Long userId) {
        return this.baseMapper.listUserCollection(projectId,userId);
    }
}
